package scalab.core.component

/**
* The <code>Universe</code> object is an abstraction 
* of all the resources. It only purpose is to be 
* pattern matched on. For instance, a directory filter 
* may react differently when connected to the universe:
* 
*	<code>
* class DirectoryFilter(dir: String) extends Filter{
*		def execute: Boolean = {
*		}
*	}
*/
import scalab.core.gates.{Input, Output}
case object Universe extends Component/*("Universe")*/{

	import scala.collection.immutable.{Set, HashSet}

	override val name: String = "Universe"
	identifier = "U" //short identifier for faster md5
	def updateId: String = {
		warning(identifier)
		identifier
	}
	def instanceId = ""
	override val out: Output = {
		val self = this
		new Output{
			override val component = self
		}
	}
	def productDirs: List[String] = Nil
	
	//implement later...
	//override private[core] def upToDate(fresh: List[Buildable]): Pair[Boolean, List[Buildable]] = (true, Nil)
	

	final private[core] def update(
		visited: Set[Component], 
		cycles: Set[(Output, Input)], 
		fresh: Set[ExecutableComponent]): (
			Boolean, 
			Set[Component], 
			Set[(Output, Input)], 
			Set[ExecutableComponent]
		) = {
			fireUpdateStarted
			val res = (true, visited, cycles, fresh)
			fireUpdateFinished(res._1)
			res
		}

	//assumption with the upToDate Algorithm:
	//universe resource set did not change
	//(same files but not the same content)
	final private[core] def upToDate(
		products: Set[Resource],
		visited: Set[Component], 
		cycles: Set[(Output, Input)], 
		fresh: Set[ExecutableComponent]): (
			Boolean, 
			Set[Component], 
			Set[(Output, Input)], 
			Set[ExecutableComponent]
		) = (true, visited, cycles, fresh)

  final private[core] def validate(validated: Set[Buildable]): Pair[Boolean, Set[Buildable]] = 
		(true, validated)

	final private[core] def validate(
		visited: Set[Component], 
		cycles: Set[(Output, Input)], 
		validated: Set[SinkComponent]): (
			Boolean, 
			Set[Component], 
			Set[(Output, Input)], 
			Set[SinkComponent]
		) = (true, visited, cycles, validated)
}
